home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
5_5c3_6.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
2KB
|
71 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ print out the tree in assembly format
/ 8086 version
/ initialize for the 8086
/ set up register bp for the stack
oid setup()
cout << "\tpush bp\n" <<
"\tmov bp, sp\n";
/ finish things up
oid finishup(stackalloc &stacktop)
cout << "\tmov ax, ";
stacktop.print(cout) << "\n";
cout << "\tmov result, ax\n";
cout << "\tpop bp\n";
/ print out a binary operator followed by the
/ source and destination
tatic void binop(const tree *head,
stackalloc &curloc, const intalloc *cursp)
assemblyprint(head->left, curloc, cursp);
stackalloc newloc(cursp);
assemblyprint(head->right, newloc, cursp);
cout << "\tmov ax,";
curloc.print(cout) << "\n";
cout << "\tmov bx,";
newloc.print(cout) << "\n";
switch (head->type)
{
case PLUS: cout << "\tadd ax, bx\n"; break;
case MUL: cout << "\tmul bx\n"; break;
case DIV: cout << "\tmov dx, 0\n" <<
"\tdiv bx\n"; break;
case MINUS: cout << "\tsub ax, bx\n"; break;
}
cout << "\tmov ";
curloc.print(cout) << ", ax\n";
/ print out a unary operator followed
/ by the destination
tatic void negop(const tree *head,
stackalloc &curloc, const intalloc *cursp)
stackalloc newloc(cursp);
assemblyprint(head->left, newloc, cursp);
cout << "\tmov ax, ";
newloc.print(cout) << "\n";
cout << "\tneg ax";
cout << "\tmov ";
curloc.print(cout) << ", ax\n";
/ store a number node at the current location
tatic void svnumber(tree* head, stackalloc &curloc)
cout << "\tmov ";
curloc.print(cout) << ", " << head->value << "\n";